﻿using System;
using Caliburn.Micro;

namespace OPSYS_Schematic.UIInfrastructure
{
    /// <summary>
    /// Denotes an option page which contains the options.
    /// </summary>
    public interface IOptionPage : ILocalizableDisplay
    {
        void Cancel();
        void Commit();
        void Load(IConfigurationObject value);
    }

    /// <summary>
    /// A base class for various implementations of <see cref="IOptionPage"/>.
    /// </summary>
    public abstract class OptionPageBase : PropertyChangedBase, IOptionPage
    {
        private string _displayName = string.Empty;
        private string _name = string.Empty;

        public OptionPageBase(string name)
        {
            Name = name;
            this.AutoUpdate(true);
        }

        #region IOptionPage Members

        public virtual void Cancel()
        {
            //Do nothing by default
        }

        public abstract void Commit();

        public void Load(IConfigurationObject value)
        {
            throw new NotImplementedException();
        }

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                NotifyOfPropertyChange(() => Name);
            }
        }

        public string DisplayName
        {
            get { return _displayName; }
            set
            {
                _displayName = value;
                NotifyOfPropertyChange(() => DisplayName);
            }
        }

        public void Handle(LanguageChangedMessage message)
        {
            this.UpdateDisplayName();
        }

        #endregion
    }
}